/** 
 *  @config  请求baseUrl
 *  @judgment  请求失败或成功 反馈用户
 */

import config from '@/common/baseUrl'
import judgment from '@/common/judgment.js'
export default async function request (url, params = {}, method = "GET") {
  return new Promise((resolve, reject) => {
    uni.request({
      url: config.baseUrl + url,
      data: params,
      method: method,
      dataType: 'json',
      header: Object.assign({
        'content-type': 'application/json',
        'X-Access-Token': uni.getStorageSync("token") || ''
      }),
      success: (res) => {
        judgment(res.data)
        resolve(res.data)
      },
      fail: (err) => {
        console.log('err', err)
        uni.hideLoading()
        uni.showModal({
          title: '',
          content: '系统忙，请重试！',
          showCancel: false,
        })
        reject(err)
      },
      complete () {
        setTimeout(() => {
          uni.hideLoading()
        }, 500)
      }
    })
  })

}
